package com.chenyaowei.web.controller.ware;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chenyaowei.common.annotation.Log;
import com.chenyaowei.common.core.controller.BaseController;
import com.chenyaowei.common.core.domain.AjaxResult;
import com.chenyaowei.common.enums.BusinessType;
import com.chenyaowei.ware.domain.CywWareSku;
import com.chenyaowei.ware.service.ICywWareSkuService;
import com.chenyaowei.common.utils.poi.ExcelUtil;
import com.chenyaowei.common.core.page.TableDataInfo;

/**
 * 库存管理Controller
 *
 * @author 陈耀威
 * @date 2023-11-25
 */
@RestController
@RequestMapping("/ware/sku")
public class CywWareSkuController extends BaseController
{
    @Autowired
    private ICywWareSkuService cywWareSkuService;

    /**
     * 查询库存管理列表
     */
    @PreAuthorize("@ss.hasPermi('ware:sku:list')")
    @GetMapping("/list")
    public TableDataInfo list(CywWareSku cywWareSku)
    {
        startPage();
        List<CywWareSku> list = cywWareSkuService.selectCywWareSkuList(cywWareSku);
        return getDataTable(list);
    }

    /**
     * 导出库存管理列表
     */
    @PreAuthorize("@ss.hasPermi('ware:sku:export')")
    @Log(title = "库存管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CywWareSku cywWareSku)
    {
        List<CywWareSku> list = cywWareSkuService.selectCywWareSkuList(cywWareSku);
        ExcelUtil<CywWareSku> util = new ExcelUtil<CywWareSku>(CywWareSku.class);
        util.exportExcel(response, list, "库存管理数据");
    }

    /**
     * 获取库存管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ware:sku:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cywWareSkuService.selectCywWareSkuById(id));
    }

    /**
     * 新增库存管理
     */
    @PreAuthorize("@ss.hasPermi('ware:sku:add')")
    @Log(title = "库存管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CywWareSku cywWareSku)
    {
        return toAjax(cywWareSkuService.insertCywWareSku(cywWareSku));
    }

    /**
     * 修改库存管理
     */
    @PreAuthorize("@ss.hasPermi('ware:sku:edit')")
    @Log(title = "库存管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CywWareSku cywWareSku)
    {
        return toAjax(cywWareSkuService.updateCywWareSku(cywWareSku));
    }

    /**
     * 删除库存管理
     */
    @PreAuthorize("@ss.hasPermi('ware:sku:remove')")
    @Log(title = "库存管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cywWareSkuService.deleteCywWareSkuByIds(ids));
    }
}
